//Accepte
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

inline int mod(int x){
	return x<0?-x:x;
}
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	int x, n, i, j, a, b, aa, bb, p, q;
	
	scanf("%d%d", &n, &x);
	p= -2e9;
	q= 2e9;
	for(i=0;i<n;++i){
		scanf("%d%d", &aa, &bb);
		if(aa>bb){
			a=bb;
			b=aa;
		}
		else{
			a=aa;
			b=bb;
		}
		if(a>p)p=a;
		if(b<q)q=b;
	}
	
	if(p>q){
		printf("-1");
	}
	else{
		if(p<=x&&x<=q)printf("0");
		else{
			aa=mod(x-p);
			bb=mod(x-q);
			printf("%d",aa<bb?aa:bb);
		}
	}
	
	return 0;
}
